#include "datasuite.h"


#include <QTimer>


DataSuite::DataSuite(DataSuite *parent) :
    DataContainer(parent),
    d(new Data())
{
    qRegisterMetaType<MetaData>("MetaData");
    connect(this, SIGNAL(sigResolveMetaData(MetaData*)), this, SLOT(onResolveMetaData(MetaData*)), Qt::DirectConnection);
    QTimer::singleShot(0, this, SLOT(onCreateMetaData()));
}

DataSuite::DataSuite(const DataSuite &other) :
    DataContainer(qobject_cast<DataSuite*>(other.parent())),
    d(other.d)
{
    connect(this, SIGNAL(sigResolveMetaData(MetaData*)), this, SLOT(onResolveMetaData(MetaData*)), Qt::DirectConnection);
}

MetaData *DataSuite::metaData() const
{
    if (d->meta.isNull())
    {
        MetaData* meta = findChild<MetaData*>();
        if (meta && meta->parent() == this)
        {
            emit sigResolveMetaData(meta);
        }
    }

    return d->meta;
}

MetaData *DataSuite::containerMetaData() const
{
    return metaData();
}

void DataSuite::onResolveMetaData(MetaData *metaData)
{
    d->meta = metaData;
}

void DataSuite::onCreateMetaData()
{
    if (!metaData())
    {
        d->meta = new MetaData(this);
    }
}

